<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>正则表达式测试</title>
    <script>
        window.onload = function(){
            document.getElementById("btn").onclick = function () {
                var reg = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
                var yourinput = document.getElementById("test").value;
                alert(reg.test(yourinput));
            }
        }
    </script>
</head>
<body>
    <input type="text" id="test">
    <input type="button" id="btn" value="测试">
</body>
</html>